package com.hxzy.shop.controller;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.common.dto.store.req.ChangeStorePwdReq;
import com.hxzy.shop.common.dto.store.req.StoreListReq;
import com.hxzy.shop.common.dto.store.resp.SameCityDeliveryResp;
import com.hxzy.shop.common.dto.store.resp.StoreDetailResp;
import com.hxzy.shop.common.dto.store.resp.StoreListResp;
import com.hxzy.shop.common.dto.store.resp.StoreNumResp;
import com.hxzy.shop.service.StoreService;
import com.hxzy.shop.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Objects;

/**
 * 功能描述:门店管理
 *
 * @author tonneyyy
 */
@RestController
@Api(tags = "门店管理")
@RequestMapping("/store")
public class StoreController {


    @Autowired
    private StoreService storeService;


    @ApiOperation(value = "门店列表", notes = "门店列表")
    @GetMapping(value = "/list")
    public Result<PageInfo<StoreListResp>> storeList(@Validated   StoreListReq req) {
        return Result.success(this.storeService.storeList(req));
    }

    @ApiOperation(value = "门店数量", notes = "商户总店数量以及已开店数量")
    @GetMapping(value = "/storeNum")
    public Result<StoreNumResp> storeNum() {
        return Result.success(this.storeService.storeNum());
    }

    @ApiOperation(value = "门店详情", notes = "门店详情")
    @GetMapping(value = "/storeDetail/{storeId}")
    public Result<StoreDetailResp> storeDetail(@PathVariable(value = "storeId") Long storeId){
        if(Objects.isNull(storeId)){
           return Result.failed("门店Id不能为空");
        }
        return Result.success(this.storeService.storeDetail(storeId));
    }

    /**
     * 判断门店是否支持门店配送
     * @param storeId
     * @return
     */
    @ApiOperation(value = "判断门店是否支持门店配送", notes = "门店详情")
    @GetMapping(value = "/checkSameCityDelivery/{storeId}")
   public Result<SameCityDeliveryResp> checkSameCityDelivery(@PathVariable(value = "storeId") Long storeId){
        if(Objects.isNull(storeId)){
            return Result.failed("门店Id不能为空");
        }
      return Result.success(this.storeService.checkSameCityDelivery(storeId));
   }


   @ApiOperation(value = "修改门店帐号的密码", notes = "修改门店帐号的密码")
   @PostMapping(value = "/changeStorePwd")
    public Result<Object> changeStorePwd(@RequestBody @Valid ChangeStorePwdReq req){
       return Result.success(this.storeService.changeStorePwd(req));
   }

}
